package SingleSort;

public class objectSort {
	public static void main(String[] args) {
		ArrayInOb arr = new ArrayInOb(100);
		arr.insert("A", "B", 18);
		arr.insert("C", "aa", 18);
		arr.insert("F", "B", 18);
		arr.insert("B", "B", 18);
		arr.insertionSort();
		arr.display();
	}
}

class Person{
	private String lastName;
	private String firstName;
	private int age;
	
	public Person(String last, String first, int a) {
		this.lastName = last;
		this.firstName = first;
		this.age = a;
	}
	
	public void displayPerson() {
		System.out.println("Last Name :"+this.lastName);
		System.out.println("First Name :"+this.firstName);
		System.out.println("Age :"+this.age);
	}
	
	public String getLast() {
		return this.lastName;
	}
}

class ArrayInOb{
	private Person[] a;
	private int nElem;
	
	public ArrayInOb(int max) {
		this.a = new Person[max];
		this.nElem = 0;
	}
	
	public void insert(String last, String first, int age) {
		this.a[this.nElem] = new Person(last, first, age);
		this.nElem++;
	}
	
	public void display() {
		for(int i=0;i<this.nElem;i++) {
			a[i].displayPerson();
			System.out.println(" ");
		}
	}
	
	public void insertionSort() {
		int in,out;
		
		for(out=1;out<this.nElem;out++) {
			Person temp = a[out];
			in = out;
			while(in>0 && this.a[in-1].getLast().compareTo(temp.getLast())>0) {
				a[in] = a[in-1];
				--in;
			}
			this.a[in] = temp;
		}
	}
}

